package com.shuoyue.ycgk.ui.recruitment.resume.major;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.MajorSection;
import com.shuoyue.ycgk.entity.MajorType;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

public class MajorSectionAdapter extends AppBaseQuickAdapter<MajorSection> {
    MajorTypeAdapter.SelectCallback selectCallback;

    public MajorSectionAdapter(@Nullable List<MajorSection> data, MajorTypeAdapter.SelectCallback selectCallback) {
        super(R.layout.item_major_section, data);
        this.selectCallback = selectCallback;

    }

    @Override
    protected void convert(BaseViewHolder helper, MajorSection item) {
        helper.addOnClickListener(R.id.name);
        helper.setText(R.id.name, item.getName());
        helper.setGone(R.id.recycleView, item.isSelect());
        helper.setImageResource(R.id.indication, item.isSelect() ?
                R.mipmap.icon_arrow_up : R.mipmap.icon_arrow_down);

        RecyclerView recyclerView = helper.getView(R.id.recycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        if (recyclerView.getTag() == null) {
            recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 4), false));
            recyclerView.setTag("tag");
        }
        MajorTypeAdapter adapter = new MajorTypeAdapter(item.getTypes(), selectCallback);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener((adapter1, view, position) -> {
            MajorType type = (MajorType) adapter1.getItem(position);
            type.setSelect(!type.isSelect());
            adapter1.notifyDataSetChanged();
        });

    }
}
